package com.razorthink.shell.utils;

import java.io.File;
import java.util.UUID;

public class SourceFileGenerator {
	public static File getGeneratedFile(String directoryName,
			String preferredFilename, String fileExtension) {
		if (preferredFilename == null) {
			preferredFilename = "";
		}
		File dir = new File(directoryName);
		if (!dir.exists()) {
			dir.mkdirs();
		}
		File srcFile = new File(dir.getAbsolutePath() + File.separator
				+ "generated-src-" + preferredFilename
				+ UUID.randomUUID().toString() + "." + fileExtension);
		return srcFile;
	}

	public static void deleteGeneratedFiles(File srcFilePath) {
		if (srcFilePath.exists()) {
			srcFilePath.delete();
			File compiled = new File(srcFilePath.getAbsoluteFile() + "c");
			if (compiled.exists()) {
				compiled.delete();
			}
		}
	}
}
